package com.supplychainapi.common;

import com.github.pagehelper.PageInfo;
import com.supplychainapi.domain.FinderPageInfoEntity;
import com.supplychainapi.param.ColTitle;
import com.supplychainapi.utils.StringUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

@ApiModel("finder列表")
public class FinderList<T> {
    @ApiModelProperty("列表唯一id")
    private String fsFinderId;
    @ApiModelProperty("标题")
    private List<ColTitle> colTitle;
    @ApiModelProperty("内容")
    private T colContent;
    @ApiModelProperty("分页信息")
    private FinderPageInfoEntity pageInfo;

    public FinderList() {

    }

    public FinderList(String fsFinderId, List<ColTitle> colTitles, T data, FinderPageInfoEntity finderPageInfoEntity) {
        this.fsFinderId = fsFinderId;
        this.colTitle = colTitles;
        this.colContent = data;
        this.pageInfo = finderPageInfoEntity;
    }

    public static final <TT> FinderList build(String fsFinderId, List<ColTitle> colTitles, TT colContent, PageInfo pageInfo) {
        FinderPageInfoEntity finderPageInfoEntity = new FinderPageInfoEntity();
        finderPageInfoEntity.setPageNum(pageInfo.getPageNum());
        finderPageInfoEntity.setPages(pageInfo.getPages());
        finderPageInfoEntity.setPageSize(pageInfo.getPageSize());
        finderPageInfoEntity.setTotal(pageInfo.getTotal());
        return new FinderList(fsFinderId, colTitles, colContent, finderPageInfoEntity);
    }

    public static final <TT, M> FinderList build(Class<? extends M> cClass, List<ColTitle> colTitles, TT colContent, PageInfo pageInfo) {
        String finderId = StringUtil.getMethodName(cClass);
        return build(finderId, colTitles, colContent, pageInfo);
    }

    public static final <TT, M> FinderList build(Class<? extends M> cClass, List<ColTitle> colTitles, PageInfo pageInfo) {
        String finderId = StringUtil.getMethodName(cClass);
        TT colContent = (TT) pageInfo.getList();
        return build(finderId, colTitles, colContent, pageInfo);
    }

    public static final <TT, M> FinderList build(Class<? extends M> cClass, List<ColTitle> colTitles, TT colContent) {
        String finderId = StringUtil.getMethodName(cClass);
        return new FinderList(finderId, colTitles, colContent, null);
    }

    public String getFsFinderId() {
        return fsFinderId;
    }

    public void setFsFinderId(String fsFinderId) {
        this.fsFinderId = fsFinderId;
    }

    public List<ColTitle> getColTitle() {
        return colTitle;
    }

    public void setColTitle(List<ColTitle> colTitle) {
        this.colTitle = colTitle;
    }

    public T getColContent() {
        return colContent;
    }

    public void setColContent(T colContent) {
        this.colContent = colContent;
    }

    public FinderPageInfoEntity getPageInfo() {
        return pageInfo;
    }

    public void setPageInfo(FinderPageInfoEntity pageInfo) {
        this.pageInfo = pageInfo;
    }

}
